//
//  WMGuideViewController.m
//  WaiMai
//
//  Created by Angela on 2017/8/24.
//  Copyright © 2017年 Angela. All rights reserved.
//

#import "WMGuideViewController.h"

@interface WMGuideViewController ()<UIScrollViewDelegate,UIGestureRecognizerDelegate>
{
    UIImageView *guideView;
}
@property (strong, nonatomic) UIScrollView *scroll;
@end

@implementation WMGuideViewController
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initWithGuideView];
    }
    return self;
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.scroll = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    self.navBarHidden = YES;
    self.scroll.delegate = self;
    self.scroll.bounces = NO;
    [self.view addSubview:self.scroll];
    [self initWithGuideView];
}
#pragma mark - subviews
- (void)initWithGuideView
{
    _scroll.pagingEnabled = true;
    _scroll.showsHorizontalScrollIndicator = NO;
    _scroll.showsVerticalScrollIndicator = NO;
    _scroll.autoresizingMask = self.view.autoresizingMask;
    _scroll.scrollsToTop = NO;
    for (int i = 1; i < 5; i++) {
        guideView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth * (i - 1), 0, ScreenWidth, ScreenHeight)];
        guideView.tag = i;
        NSString *imgName;
        imgName = [NSString stringWithFormat:@"Guide%d", i];
        UIImage *img = [UIImage imageNamed:imgName];
        guideView.image = img;
        guideView.userInteractionEnabled = YES;
        [self.scroll addSubview:guideView];
        self.scroll.contentSize = CGSizeMake(ScreenWidth * (i), 0);
        if (guideView.tag == 4) {
            UIButton *btnImg = [[UIButton alloc] init];
            [btnImg setBackgroundImage:[UIImage imageNamed:@"GuidButton"] forState:UIControlStateNormal];
            [btnImg sizeToFit];
            btnImg.frame=rect(0,self.view.height - realValue6(215), btnImg.width, btnImg.height);
            btnImg.centerX=self.view.centerX;
            [btnImg addTarget:self action:@selector(closeView:) forControlEvents:UIControlEventTouchUpInside];
            [guideView addSubview:btnImg];
        }
    }
}

#pragma mark - button click

- (void)closeView:(id)sender
{
    //写入数据
    NSUserDefaults *isFirst=[[NSUserDefaults alloc]init];
    [isFirst setObject:@"GuideFirst" forKey:@"NO"];
    WMBaseTabBarViewController *tabVC=[[WMBaseTabBarViewController alloc]init];
    [[UIApplication rootViewController] setViewControllers:@[tabVC]];
    [[NSNotificationCenter defaultCenter] postNotificationName:SXSApplicationRootControllerChangedNotification object:nil];
}
@end
